pub mod cbase;
pub mod omron;
pub mod s7;

use super::{
    err, err_value, json, ok, throw_err, Bytes, ConTcp, Connect, ECode, MapSv, RNull, Resp,
    S7Client, VBase, VMap, Value, VecV,
};
use cbase::{get_connect, write_bool, write_float, write_str, write_val};

pub async fn doit(data: Value, plc: &str, cmd: &str, connect: &Connect) -> Resp {
    let para = data.as_object().ok_or(format!("data format wrong."))?;

    match plc {
        "omron" => {
            let mut v = omron::Omron;
            v.do_cmd(para, cmd, connect).await
        }
        "s7" => {
            let mut v = s7::S7;
            v.do_cmd(para, cmd, connect).await
        }
        _ => throw_err!(ECode::NoServe, "no cmd"),
    }
}
